<?php
abstract class ZeusLib_Resource_Collection extends ZeusLib_Object
{

	/**
	 * Filter operation constants
	 *
	 * @var string
	 */
	CONST FILTER_OP_EQ  = 'e';   // Equivalent
	CONST FILTER_OP_NO  = 'ne';  // Not equivalent
	CONST FILTER_OP_GT  = 'gt';  // Greater than
	CONST FILTER_OP_GTE = 'gte'; // Greater than equivalent
	CONST FILTER_OP_LT  = 'lt';  // Less than
	CONST FILTER_OP_LTE = 'lte'; // Less than equivalent

	/**
	 * Filter object
	 * 
	 * @var ZeusLib_Resource_Filter
	 */
	protected $filter;

	/**
	 * Whether the collection is loaded flag
	 *
	 * @var boolean
	 */
	private $_isLoaded = false;


	/**
	 * Loads the data.
	 */
	abstract public function load();

	protected function _construct()
	{
		// Check whether the object is not chached
		if(!$this->isCached())
		{
			// Initialize the filter object
			$this->filter = new ZeusLib_Resource_Filter();
		}
	}

	/**
	 * Adds a collection filter to this instance.
	 *
	 * @param string $name
	 * @param string $value
	 * @param string $op
	 */
	public function addFilter($name, $value, $op = self::FILTER_OP_EQ)
	{
		// Append filter data to the filter ZeusLib_Object as a new array element
		$this->filter->addDataToArray($name, $op, $value);
	}

	/**
	 * Sets the whether the collection is loaded.
	 *
	 * @param boolean $flag
	 */
	protected function setIsLoaded($flag)
	{
		// Change flag
		$this->_isLoaded = (bool)$flag;
	}

	/**
	 * Gets whether the collection is loaded.
	 *
	 * @return boolean
	 */
	public function getIsLoaded()
	{
		// Return flag
		return $this->_isLoaded;
	}

	public function getIterator()
	{
		// Check whether we loaded this collection
		if(!$this->getIsLoaded())
		{
			// Load the collection
			$this->load();
		}
		
		// Return super getIterator
		return parent::getIterator();
		
		// TODO: remove
		// Return instance of ZeusLib_Object with already implemented getIterator
		//return $this->getCollection();
	}

}